package ui.magic.magiclibs.container.LittleThings;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.support.v7.widget.AppCompatButton;
import android.util.AttributeSet;

import ui.magic.magiclibs.container.Drawable.PowerDrawable;

/**
 * Created by liushiyin on 2017/10/25.
 */

public class RoundButton extends AppCompatButton {

    private PowerDrawable powerDrawable;

    public RoundButton(Context context) {
        super(context);
        init();
    }

    public RoundButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public RoundButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        powerDrawable=new PowerDrawable();
        this.setBackground(powerDrawable);
    }

    public void setCircle(boolean b){
        powerDrawable.setCircle(b);
    }

    public void setRoundWidth(int width){
        powerDrawable.setRoundWidth(width,width);
    }

    public void setBackgroundColor(int color){
        powerDrawable.setColor(color);
    }

    public void setBackgroundImage(Bitmap bitmap){
        powerDrawable.setBitmap(bitmap);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width = getMeasuredWidth();
        int height = getMeasuredHeight();
        powerDrawable.setBounds(0, 0, width, height);
    }
}
